import java.util.Arrays;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:空调控制
 * User: wangxin
 * Date: 2024-09-25
 * Time: 17:42
 */
public class test3 {


        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            int n = in.nextInt();
            int p = in.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = in.nextInt();
            }
            Arrays.sort(arr);
            p *= 2;
            int ret = 0;
            int left = 0;
            int right = 0;
            while (right < n) {
                while (arr[right] - arr[left] > p) {
                    left++;
                }
                ret = Math.max(ret,right - left + 1);
                right++;
            }
            System.out.println(ret);
        }

}
